tools/python: Replace python string exceptions with ValueError exceptions
authorMatthias Klose <doko@debian.org>
Tue, 14 Sep 2010 16:46:21 +0000 (17:46 +0100)
committerMatthias Klose <doko@debian.org>
Tue, 14 Sep 2010 16:46:21 +0000 (17:46 +0100)
There are at least some syntax errors when trying to use the xen utils with
python2.6.  The attached patch changes these string exception into
ValueErrors:

   - tools/python/xen/util/bugtool.py (getBugTitle)
   - tools/python/xen/xend (class XendBase): not catched
   - tools/python/xen/xm/xenapi_create.py (sxp2xmlconvert_sxp_to_xml):
     the method already raises a ValueError for similiar condition.
   - tools/python/xen/xm/main.py (xm_network_attach): not catched.

For all but maybe the first one, the replacement of the string
exceptions into ValueErrors seems to be safe.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/python/xen/util/bugtool.py
tools/python/xen/xend/XendBase.py
tools/python/xen/xm/main.py
tools/python/xen/xm/xenapi_create.py

index 18569dcb330cbea2f3a487bac2881b5a57c74c38..e8d96b884af37e78d715324f97e57126f6fcb30e 100644 (file)
@@ -141,7 +141,7 @@ def getBugTitle(bug):
     finally:
         f.close()
 
-    raise "Could not find title of bug %d!" % bug
+    raise ValueError("Could not find title of bug %d!" % bug)
 
 
 def send(bug, conn, fd, filename, username, password):
index 73fed471dce6af99f9cb235f94b730d8ce26a8c5..924477669aab9c46aae3d34f6fb54346b9ee591a 100644 (file)
@@ -115,7 +115,7 @@ class XendBase:
             # In OSS, ref == uuid
             return uuid
         else:
-            raise "Big Error.. TODO!"
+            raise ValueError("Big Error.. TODO!")
 
     def get_all_records(cls):
         return dict([(inst.get_uuid(), inst.get_record())
index e0e3d154b2f437cf9d590a5abcd17dafaf851636..d7fd81be912bc4cca63e3f704ca20326d7af392c 100644 (file)
@@ -2796,7 +2796,7 @@ def xm_network_attach(args):
                              for ref, record in server.xenapi.network
                              .get_all_records().items()])
             if bridge not in networks.keys():
-                raise "Unknown bridge name!"
+                raise ValueError("Unknown bridge name!")
             return networks[bridge]
 
         vif_conv = {
index ca8adc0a10563b4cfc80caa74195e2ec6645f6c3..efe96ebd82e3169d481fdb509caa0d9ee63db00f 100644 (file)
@@ -707,7 +707,7 @@ class sxp2xml:
                 vm.attributes['security_label'] = \
                                     security.set_security_label(sec_data[0][1][1],sec_data[0][2][1])
             except Exception, e:
-                raise "Invalid security data format: %s" % str(sec_data)
+                raise ValueError("Invalid security data format: %s" % str(sec_data))
 
         # Make the name tag